// readers/factory.go
package readers

import (
	"fmt"
	"mig2kwdb/common"
	dameng "mig2kwdb/readers/dameng"
	mysql "mig2kwdb/readers/mysql"
	oracle "mig2kwdb/readers/oracle"
	postgresql "mig2kwdb/readers/postgresql"
	sqlserver "mig2kwdb/readers/sqlserver"
	tdengine "mig2kwdb/readers/tdengine"

	"strings"
)

func CreateReader(dbConn common.DBConnectionInfo) (Reader, error) {
	switch strings.ToLower(dbConn.Dbtype) {
	case "mysql", "tidb":
		return mysql.NewMySQLReader(dbConn)
	case "sqlserver":
		return sqlserver.NewSQLServerReader(dbConn)
	case "postgresql", "postgres":
		return postgresql.NewPostgreSQLReader(dbConn)
	case "oracle":
		return oracle.NewOracleReader(dbConn)
	case "tdengine":
		return tdengine.NewTDengineReader(dbConn)
	case "dameng":
		return dameng.NewDamengReader(dbConn)
	default:
		return nil, fmt.Errorf("unsupported database type: %s", dbConn.Dbtype)
	}
}
